<?php
use yii\helpers\Html;
use \backend\controllers\DtActionFilter;
$project_id = Yii::$app->request->get("project_id");

if (!empty($project_id)){
    $isView = DtActionFilter::checkProject('project_edit',$project_id);
}else{
    $isView=true;
    return '无用户id';
}
?>
<div class="container containerShadow">
    <div class="row ">
        <div class="topimg">
            <div class="left pull-left">
                <span>回现评估</span>
            </div>
            <div class="pull-right">
                <a href="javascript:;">
                    <?php
                    if ($isView){
                        echo Html::img("/image/projectDetails/edit.png",["id"=>"getPingGu","data-val"=>4]);
                    }
                    ?>
                </a>
            </div>
        </div>
        <form action="" class="pingguW">

            <table class='tableRaius huiXian huiXianList' border="0" cellspacing="0" cellpadding="0" style="border-collapse:separate;border-spacing: 0; border: 1px solid #E2E2E2;">
                <tr>
                    <td>回现保守</td>
                    <td>
                    	<pre><?= !empty($payment['payment_reservation'])?\common\helps\formatMoney::format_money($payment['payment_reservation']):''?></pre>
                    </td>
                    <td>回现激进</td>
                    <td>
                    	<pre><?= !empty($payment['payment_radical'])?\common\helps\formatMoney::format_money($payment['payment_radical']):''?></pre>
                    </td>
                </tr>
                <tr>
                    <td>过户税费</td>
                    <td>
                        <input style="padding-left: 0;" type="text" readonly="readonly" name="" id="" title="过户税费"
                               value="<?= !empty($payment['payment_tax'])?\common\helps\formatMoney::format_money($payment['payment_tax']):''?>"
                        />
                    </td>
                    <td>回现周期（月）</td>
                    <td>
                        <input style="padding-left: 0;" type="text" readonly="readonly" name="" id="" title="回现周期（月）" value="<?= !empty($payment['payment_month'])?$payment['payment_month']:''?>" />
                    </td>
                </tr>
                <tr>
                    <td>回现分析</td>
                    <td colspan="3" rowspan="2">
                    	   <pre><?= !empty($payment['payment_analysis'])?$payment['payment_analysis']:''?></pre>
                     <!--   <input style="padding-left: 0;" type="text" readonly="readonly" name="" id="" title="回现分析" value="<?= !empty($payment['payment_analysis'])?$payment['payment_analysis']:''?>" />-->
                    </td>
                </tr>
            </table>

        </form>
        <form action="" style="display: none;" class="pingguEdit">
            <table class='tableRaius huiXian editTable' border="0" cellspacing="0" cellpadding="0" style="border-collapse:separate;border-spacing: 0;">
                <tr>
                    <td>回现保守</td>
                    <td>
                        <input type="text" name="" id="payment_reservation_huixian"  onchange="checkNumber('payment_reservation_huixian')"  value="<?= !empty($payment['payment_reservation'])?$payment['payment_reservation']:''?>" />
                    </td>
                    <td class="text-center">回现激进</td>
                    <td>
                        <input type="text" name="" id="payment_radical_huixian"  onchange="checkNumber('payment_radical_huixian')"   value="<?= !empty($payment['payment_radical'])?$payment['payment_radical']:''?>" />
                    </td>
                </tr>
                <tr>
                    <td>过户税费</td>
                    <td>
                        <input type="text" name="" id="payment_tax" onchange="checkNumber('payment_tax')" value="<?= !empty($payment['payment_tax'])?$payment['payment_tax']:''?>" />
                    </td>
                    <td class="text-center">回现周期（月）</td>
                    <td>
                        <input type="text" name="" id="payment_month" onchange="checkNumber('payment_month')" value="<?= !empty($payment['payment_month'])?$payment['payment_month']:''?>" />
                    </td>
                </tr>
                <tr>
                    <td>回现分析</td>
                    <td colspan="3" rowspan="2">
                        <textarea name="" rows="" cols="" class="textarea-edit" id="payment_analysis"><?= !empty($payment['payment_analysis'])?$payment['payment_analysis']:''?></textarea>
                    </td>
                </tr>
            </table>

            <div class="cancelInConfirm clearfix">
                <input id="ajaxPG" class="cancelInConfirmActive" type="button" value="保存" />
                <input id='cancelPG' type="button" value="取消" />
            </div>
        </form>
    </div>
</div>

    	<!-- textarea 高度设置对比div -->
	
	<div style="max-height: 1px; overflow: hidden;">
		
		<div id="d1" style="visibility:hidden;min-height: 80px;"></div>
	
	</div>
<script>
    $(function () {
    	// textarea 高度展示问题
	    $(".textarea-edit").keyup(function(){
	         
	      var val = $(this).val();
	      $("#d1").html("<pre>" +val+" "+"</pre>");
	      var h = $("#d1").height() ;
	      $(this).height(h);
	    });

        var payment_reservation    = ''; //项目名称
        var payment_radical    = ''; //项目编号
        var payment_tax = ''; //项目类型
        var payment_month = '';   //省份
        var payment_analysis = '';
        $('#ajaxPG').click(function(){
            payment_reservation = $("#payment_reservation_huixian").val();
            payment_radical = $("#payment_radical_huixian").val();
            payment_tax = $("#payment_tax").val();
            payment_month = $("#payment_month").val();
            payment_analysis = $("#payment_analysis").val();
            //--------------------------项目名称/项目编号/项目类型/省份------end-------------
            var data={
                'payment_reservation':payment_reservation,
                'payment_radical':payment_radical,
                'payment_tax':payment_tax,
                'payment_month':payment_month,
                'payment_analysis':payment_analysis,
                'project_id':project_id,
                'package_id':package_id,
            };
            $.post('/project/ajax-save-payment-project',{'project_id':project_id,'data':data},function (res) {
                if (res){
                    layer.msg("更新成功");
                    baseW();
                }else{
                    layer.msg("更新失败");
                }
            })
        })
        //-----------------渲染无编辑页面--------------------
        function baseW() {
            $.get('/project/get-mortgage-view',{'project_id':project_id,'postion':4},function (res) {
                $(".pingguDOM").children().remove();
                $(".pingguDOM").html(res);
            })
        }
        $("#cancelPG").click(function () {
            $.post('/project/ajax-un-lock',{'postion':22,'project_id':project_id},function (res) {
                var JSONData = JSON.parse(res)
                if (JSONData.code == 200){
                    layer.msg(JSONData.message);
                }else{
                    layer.msg(JSONData.message);
                }
            });
            $(".pingguEdit").hide();
            $(".pingguW").show();
        })
        $("#payment_reservation_huixian,#payment_radical_huixian").keyup(function(){
            var c=$(this);
            var value_number = c.val();
            var value_number_test = value_number.replace(/,/ig,'');
            var value_number_test = value_number_test.replace(/./ig,'');
            if(/[^\d]/.test(value_number_test)){//替换非数字字符
                $("#ajaxPG").attr('disabled','true');
                c.parent().find("p").empty("");
                c.parent().append("<p style='color: red'>填写数字</p>")
            }else{
                $("#ajaxPG").removeAttr('disabled');
                c.parent().find("p").empty("");
            }
        })
    })

    function checkNumber(str){
        var c=$('#'+str);
        var value_number = c.val();
        var value_number_test = value_number.replace(/,/ig,'');
        var value_number_test = value_number_test.replace(/\./ig,'');
        if(/[^\d]/.test(value_number_test)){//替换非数字字符
            $("#ajaxPG").attr('disabled','true');
            c.parent().find("p").empty("");
            c.parent().append("<p style='color: red'>填写数字</p>")
        }else{
            $("#ajaxPG").removeAttr('disabled');
            c.parent().find("p").empty("");
        }
    }
</script>
